﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using RapidDownloader.Model;
using System.Windows.Data;

namespace RapidDownloader.Modules.Views.DownloadModule.Controls
{
    public class ListViewWithSelectedItemsNotification: ListView
    {
        public static readonly DependencyProperty HasSelectedItemsProperty = DependencyProperty.Register("HasSelectedItems", typeof(bool), typeof(ListViewWithSelectedItemsNotification), new UIPropertyMetadata(false));
        public static readonly DependencyProperty FilesProperty = DependencyProperty.Register("Files", typeof(DownloadFile[]), typeof(ListViewWithSelectedItemsNotification), new UIPropertyMetadata(null));

        protected override void OnSelectionChanged(SelectionChangedEventArgs e)
        {
            HasSelectedItems = SelectedItems != null && SelectedItems.Count > 0;
            Files = SelectedItems.OfType<DownloadFile>().ToArray();

            base.OnSelectionChanged(e);
        }

        public bool HasSelectedItems
        {
            get { return (bool)GetValue(HasSelectedItemsProperty); }
            set { SetValue(HasSelectedItemsProperty, value); }
        }

        public DownloadFile[] Files
        {
            get { return (DownloadFile[])GetValue(FilesProperty); }
            set { SetValue(FilesProperty, value); }
        }
    }
}